// 策略模式
var imgFunc = (function(){
  var imgNode = document.createElement('img')
  document.body.appendChild(imgNode)
  return {
    setSrc: function(src){
      imgNode.src = src
    }
  }
})();
var proxyImage = (function(){
  var img = new Image()

  img.onload = function(){
    imgFunc.setSrc(this.src)
  }

  return {
    setSrc: function(src){
      imgFunc.setSrc('./loading.gif')
      img.src = src
    }
  }
})();
proxyImage.setSrc('./pic.png')

// 函数的防抖节流 代理模式
var proxySynchronousFile = (function(){
  var cache = [],
      timer;
  return function(id){
    cache.push(id);
    if(timer){
      return ;
    }
    timer = setTimeout(function(){
      dosomething(cache.join(','))
      clearTimeout(timer)
      timer = null
      cache.length = 0
    }, 2000)
  }
})();



